using System;
using System.Xml;
using System.IO;
using System.Windows.Forms;
using PointOfSale.Global;
using PointOfSale.Languages;

namespace PointOfSale.POSSystem
{
	public class frmParameters : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox txtServiceTax;
		private System.Windows.Forms.TextBox txtTax;
		private System.Windows.Forms.TextBox txtExchangeRate;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		
		private System.ComponentModel.Container components = null;

		public frmParameters()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.txtExchangeRate = new System.Windows.Forms.TextBox();
			this.txtTax = new System.Windows.Forms.TextBox();
			this.txtServiceTax = new System.Windows.Forms.TextBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Service Tax(%)";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(104, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "Tax (%)";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(104, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "Exchange Rate";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnCancel);
			this.groupBox1.Controls.Add(this.btnOK);
			this.groupBox1.Controls.Add(this.txtExchangeRate);
			this.groupBox1.Controls.Add(this.txtTax);
			this.groupBox1.Controls.Add(this.txtServiceTax);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(264, 144);
			this.groupBox1.TabIndex = 3;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Parameters";
			// 
			// btnCancel
			// 
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnCancel.Location = new System.Drawing.Point(184, 104);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 23);
			this.btnCancel.TabIndex = 7;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnOK.Location = new System.Drawing.Point(112, 104);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(64, 24);
			this.btnOK.TabIndex = 6;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// txtExchangeRate
			// 
			this.txtExchangeRate.Location = new System.Drawing.Point(128, 72);
			this.txtExchangeRate.Name = "txtExchangeRate";
			this.txtExchangeRate.Size = new System.Drawing.Size(120, 20);
			this.txtExchangeRate.TabIndex = 5;
			this.txtExchangeRate.Text = "";
			this.txtExchangeRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtTax
			// 
			this.txtTax.Location = new System.Drawing.Point(128, 48);
			this.txtTax.Name = "txtTax";
			this.txtTax.Size = new System.Drawing.Size(120, 20);
			this.txtTax.TabIndex = 4;
			this.txtTax.Text = "";
			this.txtTax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtServiceTax
			// 
			this.txtServiceTax.Location = new System.Drawing.Point(128, 24);
			this.txtServiceTax.Name = "txtServiceTax";
			this.txtServiceTax.Size = new System.Drawing.Size(120, 20);
			this.txtServiceTax.TabIndex = 3;
			this.txtServiceTax.Text = "";
			this.txtServiceTax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// frmParameters
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(278, 155);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.Name = "frmParameters";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "frmParameters";
			this.Load += new System.EventHandler(this.frmParameters_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

			this.label1.Text = clsGlobal.g_Hashtable["ParaServiceTax"].ToString();
			this.label2.Text = clsGlobal.g_Hashtable["ParaTax"].ToString();
			this.label3.Text = clsGlobal.g_Hashtable["ParaExchangeRate"].ToString();
			this.groupBox1.Text = clsGlobal.g_Hashtable["Parameters"].ToString();
			this.btnOK.Text = clsGlobal.g_Hashtable["ParabtnOK"].ToString();
			this.btnCancel.Text = clsGlobal.g_Hashtable["ParabtnCancel"].ToString();
			this.Text = clsGlobal.g_Hashtable["ParametersFormName"].ToString();
		}
		#endregion

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				String taxservice= txtServiceTax.Text.Trim();
				String tax = txtTax.Text.Trim();
				String exchangeRate = txtExchangeRate.Text.Trim();

				//Ghi vao file xml
				XmlTextWriter writer = new XmlTextWriter (clsGlobal.g_AppPath + "\\Languages\\Parameters.xml", null);
				// Use indenting for readability.
				writer.Formatting = Formatting.Indented;
        
				// Write the root element.
				writer.WriteStartElement("Parameters");

				writer.WriteStartElement("Resource");
				writer.WriteAttributeString("tag", "ServiceTax");
				writer.WriteString(taxservice);
				writer.WriteFullEndElement();

				writer.WriteStartElement("Resource");
				writer.WriteAttributeString("tag", "Tax");
				writer.WriteString(tax);
				writer.WriteFullEndElement();

				writer.WriteStartElement("Resource");
				writer.WriteAttributeString("tag", "ExchangeRate");
				writer.WriteString(exchangeRate);
				writer.WriteFullEndElement();

				// Write the close tag for the root element.
				writer.WriteFullEndElement();
             
				// Write the XML to file and close the writer.
				writer.Flush();
				writer.Close();

				//Ghi tro lai cac bien.
				clsGlobal.g_ServiceTax = Convert.ToDouble(taxservice)/100;
				clsGlobal.g_Tax = Convert.ToDouble(tax)/100;
				clsGlobal.g_ExchangeRage = Convert.ToDouble(exchangeRate);
				this.Close();
			}
			catch(Exception exp)
			{
				MessageBox.Show(exp.ToString());
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void frmParameters_Load(object sender, System.EventArgs e)
		{
			clsGlobal.g_ParaHashtable = Language.GetData(clsGlobal.g_AppPath + "\\Languages\\Parameters.xml");
			txtServiceTax.Text = clsGlobal.g_ParaHashtable["ServiceTax"].ToString();
			txtTax.Text = clsGlobal.g_ParaHashtable["Tax"].ToString();
			txtExchangeRate.Text = clsGlobal.g_ParaHashtable["ExchangeRate"].ToString();
		}
	}
}
